<!DOCTYPE htm>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>多个元素或组件的过渡</title>
  <script src="./vue.js"></script>
  <style>
    .fade-enter, .fade-leave-to {
      opacity: 0;
    }
    .fade-enter-active, .fade-leave-active {
      transition: 1s;
    }
  </style>
</head>
<body>
  <div id="root">
    <!-- mode 使用 先进入再隐藏 -->
    <transition name="fade" mode="in-out">
      <!-- <child v-if="show"></child>
      <child-one v-else></child-one> -->
      <component :is="type">
        <child></child>
        <child-one></child>
      </component>
    </transition>
    <button @click="handleClick">Toggle</button>
  </div>

  <script>
    Vue.component('child', {
      template: '<div>child</div>'
    })
    Vue.component('child-one', {
      template: '<div>child-one</div>'
    })
    var vm = new Vue({
      el: '#root',
      data: {
        // show: true
        type: 'child'
      },
      methods: {
        handleClick: function() {
          // this.show = !this.show;
          this.type = this.type === 'child' ? 'child-one' : 'child';
        }
      }
    })
  </script>
</body>
</html>